<!-- 会员登陆 -->
<style>
	button.btn.btn-danger{
		padding:0px 12px;
		margin-left:10px;
		font-size:12px;
	}
</style>
<?php $id="form_".uniqid();?>
<table id="<?php echo $id;?>"></table>
<script>
    $("#<?php echo $id;?>").DataSource({url:'Cash/get_amount_summary_list',
        fields:[
            [
                {field:'in',title:'收入',align:'center',width:300,sortable:true},
                {field:'in_money',title:'收入金额',align:'center',width:300,sortable:true},
                {field:'out',title:'支出',align:'center',width:300,sortable:true},
                {field:'out_detail',title:'支出明细', align:'center', width:300,  sortable:true}
            ]

       ], tools:[
            {instant:false},
            <?php if(in_array('ADD',$auth)){?>
            {text:"新增层级",iconCls:"icon-add",handler:function(){
                $('#<?php echo $id?>').DataSource('add',{title:'新增层级',get:'level/edituser?>',full:true});
            }},
            <?php }?>
            {type:'combobox',text:'时区',width:40,name:'verify_login',value:'', items:'<option value="">美东</option><option value="1">北京</option>'},
			{type:'datebox', text:'日期',  width:100,name:'qaddtime',value:''},
			{type:'datebox', text:'-', width:100,name:'zaddtime',value:''},
			{type:'textbox', text:'账号', width:100,name:'member_account'},
			{type:'label', html:'<button class="btn btn-danger summary_btn" type="button" data="today">今日</button>', width:50},
			{type:'label', html:'<button class="btn btn-danger summary_btn" type="button" data="yesterday">昨日</button>', width:50},
			{type:'label', html:'<button class="btn btn-danger summary_btn" type="button" data="theweek">本周</button>', width:50},
			{type:'label', html:'<button class="btn btn-danger summary_btn" type="button" data="lastweek">上周</button>', width:50},
			{text:"查询", iconCls:"icon-search", handler:function(){
				$('#<?php echo $id?>').DataSource('search');
			}},
		'-'
        ],
        checkbox:false,
        edit:true,
        footer:true,
        success:function(){
            $('#<?php echo $id?>').pagination({layout:['links','last'],showRefresh:false});
        }
    });

    $(".summary_btn").click(function() {
        var dates = get_dates($(this).attr('data'));
//        console.log(dates);
        $('#qaddtime').datebox("setValue", dates[0]);
        $('#zaddtime').datebox("setValue", dates[1]);
    });

    function get_dates(type)
    {
        var startdate;
        var enddate;
        var now = new Date(); //当前日期
        var nowDayOfWeek = now.getDay(); //今天本周的第几天
        var nowDay = now.getDate(); //当前日
        var nowMonth = now.getMonth(); //当前月
        var nowYear = now.getYear(); //当前年
        nowYear += (nowYear < 2000) ? 1900 : 0;

        switch(type) {
            case 'yesterday':
                startdate = format_date(new Date(nowYear, nowMonth, nowDay - 1));
                enddate = format_date(new Date(nowYear, nowMonth, nowDay));
                break;
            case 'theweek':
                startdate = format_date(new Date(nowYear, nowMonth, nowDay - nowDayOfWeek+1));
                enddate = format_date(new Date(nowYear, nowMonth, nowDay));
                break;
            case 'lastweek':
                startdate = format_date(new Date(nowYear, nowMonth, nowDay - nowDayOfWeek-6));
                enddate = format_date(new Date(nowYear, nowMonth, nowDay-nowDayOfWeek));
                break;
            default:
                startdate = enddate = format_date(new Date()); //当前日期
        }

        return [startdate, enddate];
    }

    function format_date(date) {
        var myyear = date.getFullYear();
        var mymonth = date.getMonth()+1;
        var myweekday = date.getDate();

        if(mymonth < 10){
            mymonth = "0" + mymonth;
        }
        if(myweekday < 10){
            myweekday = "0" + myweekday;
        }
        return (myyear+"-"+mymonth + "-" + myweekday);
    }
</script>